package com.yanfan.point.controller;

import java.util.Arrays;
import java.util.List;
import javax.validation.Valid;
import javax.servlet.http.HttpServletResponse;
import com.yanfan.common.utils.DateUtils;
import com.yanfan.common.utils.SecurityUtils;
import com.yanfan.system.util.DeptTypeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.point.domain.IbmsPoint;
import com.yanfan.point.service.IIbmsPointService;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.common.core.page.TableDataInfo;

/**
 * 点位Controller
 *
 * @author genluo
 * @date 2024-10-09
 */
@Api(tags = "点位")
@RestController
@RequestMapping("/point/point")
public class IbmsPointController extends BaseController {
    @Autowired
    private IIbmsPointService ibmsPointService;

    /**
     * 查询点位列表
     */
    @ApiOperation("点位分页列表")
    @PreAuthorize("@ss.hasPermi('point:point:list')")
    @GetMapping("/list")
    public TableDataInfo list(IbmsPoint ibmsPoint) {
        startPage();
        List<IbmsPoint> list = ibmsPointService.queryPageList(ibmsPoint);
        return getDataTable(list);
    }

    /**
     * 导出点位列表
     */
    @ApiOperation("导出点位列表")
    @PreAuthorize("@ss.hasPermi('point:point:export')")
    @Log(title = "点位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IbmsPoint ibmsPoint) {
        List<IbmsPoint> list = ibmsPointService.queryPageList(ibmsPoint);
        ExcelUtil<IbmsPoint> util = new ExcelUtil<IbmsPoint>(IbmsPoint.class);
        util.exportExcel(response, list, "点位数据");
    }

    /**
     * 获取点位详细信息
     */
    @ApiOperation("获取点位详细信息")
    @PreAuthorize("@ss.hasPermi('point:point:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(ibmsPointService.getById(id));
    }

    /**
     * 新增点位
     */
    @ApiOperation("新增点位")
    @PreAuthorize("@ss.hasPermi('point:point:add')")
    @Log(title = "点位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody IbmsPoint ibmsPoint) {
        ibmsPoint.setCreateBy(SecurityUtils.getUsername());
        ibmsPoint.setCreateTime(DateUtils.getNowDate());
        return toAjax(ibmsPointService.save(ibmsPoint));
    }

    /**
     * 修改点位
     */
    @ApiOperation("修改点位")
    @PreAuthorize("@ss.hasPermi('point:point:edit')")
    @Log(title = "点位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody IbmsPoint ibmsPoint) {
        ibmsPoint.setUpdateBy(SecurityUtils.getUsername());
        ibmsPoint.setUpdateTime(DateUtils.getNowDate());
        return toAjax(ibmsPointService.updateById(ibmsPoint));
    }

    /**
     * 删除点位
     */
    @ApiOperation("删除点位")
    @PreAuthorize("@ss.hasPermi('point:point:remove')")
    @Log(title = "点位", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ibmsPointService.removeBatchByIds(Arrays.asList(ids)));
    }
}
